//
//  HZL_StoryDetailTableViewCell.m
//  B_Project
//
//  Created by 胡佳俊 on 15/11/28.
//  Copyright © 2015年 HZL. All rights reserved.
//

#import "HZL_StoryDetailTableViewCell.h"
@interface HZL_StoryDetailTableViewCell ()

@property (nonatomic, retain)UIImageView *img;
@property (nonatomic, retain)UILabel *label;

@end
@implementation HZL_StoryDetailTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createView];
    }
    return self;
}
- (void)createView
{
    self.img = [[UIImageView alloc]init];
    [self.contentView addSubview:self.img];
    
    self.label = [[UILabel alloc]init];
    self.label.font = [UIFont systemFontOfSize:15];
    self.label.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:self.label];

}



- (void)layoutSubviews
{
    
    [super layoutSubviews];
    self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    
    
    CGFloat height = (self.detailModel.photo_height).floatValue;
    CGFloat width = (self.detailModel.photo_width).floatValue;
    if (width == 0) {
        width = 1;
    }
    CGFloat h = height * WIDTH / width;
    self.img.frame = CGRectMake(20, 0, WIDTH - 40, h);
    
    CGFloat hLabel = [[self class]heightWithText:self.label.text fontSize:15 Width:WIDTH - 40];
    
    
    
    self.label.frame = CGRectMake(self.img.frame.origin.x, self.img.frame.origin.y + 0 + self.img.frame.size.height , WIDTH - 40, hLabel);
    self.label.numberOfLines = 0;
}

- (void)setDetailModel:(HZL_RecommendModel *)detailModel
{
    if (_detailModel != detailModel) {
        _detailModel = detailModel;
    }
    [self.img sd_setImageWithURL:[NSURL URLWithString:detailModel.photo] placeholderImage:nil];
    self.label.text = detailModel.text;
    
    
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
